#!/bin/sh


STAGE_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.go')
if test ${#STAGE_FILES} -gt 0
then
  echo "开始文件格式化"
  for FILE in $STAGE_FILES
    do
        echo "格式化:" $FILE
        go fmt "$FILE"
        if [[ "$?" == 1 ]]; then
          PASS=false
        else
          git add "$FILE"
        fi
    done

      if ! $PASS; then
      echo "格式化 未通过！"
      exit 1
  else
      echo "格式化 完毕!"
  fi

fi

exit $?